<?php 
App::uses('AppController', 'Controller');

class DetailController extends AppController {
	
	public function index() {
		$this->layout = 'layoutNoMenuLeft';
	}	
	/*
 	* get post by short_id
 	* @author: ThanhTran
 	* @since 2014-11-08
  	*/
	public function view($id){
		$this->loadModel('Post');
		$this->layout = 'layoutNoMenuLeft';
		$post = $this->Post->findByIdAndCheckStatus($id,1);
		if(empty($post)){
			throw new NotFoundException();
		}
		//get region_name of post
		$this->loadModel('Region');
		$region_name = $this->Region->findById($post['Post']['region_id']);

		//get category_name
		$this->loadModel('Category');
		$category_id = 0;
		$arr = explode("_", $post['Post']['category_ids']);
		$category_id = $arr[1];
		$category_name = $this->Category->findById($category_id);

		//get image url
		$this->loadModel('Image');
		$image = $this->Image->findById($post['Post']['id']);

		//get number of post images
		$numberImages = $this->Image->getNumberImages($post['Post']['id']);

		//get shop
		$this->loadModel('Shop');
		$shop = $this->Shop->findShopByCategory($category_id);
		$this->set('shop',$shop);

		//get post relative
		$posts = $this->Post->findByCategory($post['Post']['category_ids']);
		$this->set('posts',$posts);

		$this->set('post',$post);
		$this->set('categoryid',$post['Post']['id']);
		$this->set('title_for_layout',$post['Post']['title_vn']);
		$this->set('region_name',$region_name);
		$this->set('category_name',$category_name);
		$this->set('image',$image);
		$this->set('numberImages',$numberImages);
		$this->set('category_id',$category_id);

		//get banner
		$this->loadModel('Banner');
		$banners = $this->Banner->findByCategoryId($category_id);
		$this->set('banners',$banners);
	}
}
?>